﻿using System;
using System.Collections.Generic;
using MongoDB.Bson;
using Sustainalytics.ScreeningTool.BL.Model;
using Sustainalytics.Entities;
using Sustainalytics.Utils;
using Sustainalytics.ESG.Entities;
using Sustainalytics.Portfolios.BL.Model;
using Sustainalytics.ClientDW.Entities;

namespace Sustainalytics.ScreeningTool.BL
{
    public interface ICompanyScreening
    {
        #region CriteriaLevel
        CriteriaLevel1 GetCriteriaLevelOne(Guid criteriaLevel1Id);
        CriteriaLevel2 GetCriteriaLevelTwo(Guid criteriaLevel2Id);
        CriteriaLevel3 GetCriteriaLevelThree(Guid criteriaLevel3Id);
        CriteriaLevel2 GetCriteriaLevel2Id(Guid id);
        CriteriaLevel2 GetCriteriaLevelTwoByLevel3Id(Guid criteriaLevel3Id);
        List<CriteriaLevel1> ListCriteriaLevelOne();
        List<CriteriaLevel2> ListCriteriaLevelTwo(Guid? criteriaLevel1Id);
        #endregion

        List<BaseCriteria> ListBaseCriteria(Guid? criteriaLevel2Id);

        T LoadTemplateCriteria<T>(Guid criteriaTemplateId) where T : IEntity;

        List<CriteriaChartData> LoadCriteriaTypeOneData(Guid criteriaTemplateId, List<int> universeIds);
        List<CriteriaBasic> LoadCriteriaTypeThreeDataSingleItems(CriteriaTypeThree criteriaItem);
        CriteriaTypeThree LoadCriteriaTypeThreeSingleCollection(string collectionName);
        List<string> LoadCriteriaTypeThreeData(Guid templateId, List<int> universeIds, int skip, int take, string filter, out int totalCount);
        List<CriteriaTypeFour> LoadCriteriaTypeFour(Guid piFilterCriteriaId);
        CriteriaTypeFive LoadTemplateCriteriaTypeFive(Guid criteriaTemplateId);
        CriteriaType25 LoadTemplateCriteriaType25(Guid criteriaTemplateId);
        
        List<CriteriaChartData> LoadCriteriaTypeSixData(Guid criteriaTemplateId, List<int> universeIds);
        List<string> LoadCriteriaTypeSevenData(Guid templateId, List<int> universeIds, int skip, int take, string filter, out int totalCount);

        #region CriteriaType16
        CriteriaType16 LoadCriteriaType16(Guid criteriaTemplateId);
        List<CriteriaChartData> LoadCriteriaType16Data(Guid criteriaTemplateId, List<int> universeIds);
        List<Guid> ProcessCriteriaType16(CriteriaType16 criteria, Guid? portfolioId, List<int> universeIds, List<Guid> criteriaCompanies);
        #endregion

        #region Run
        List<PortfolioSecurityModel> GetClientPortfolioSecurities(Guid portfolioId, PortfolioUserClaims userClaims);

        List<BsonValue> RunSelectedCriteriaOnScreeningData(Guid filterId, Guid portfolioId, bool report, bool memoryResultOutput, Guid accountId, ScreeningReportData screeningReportData);
        List<BsonDocument> GetResultOutput(ResultOutputFilter filter, int skip, int take, string [] orderBy = null, bool asc = true);

        List<CriteriaResultOutput> GetCriteriaResultOutput(Guid filterId);

        int CountResultOutput(ResultOutputFilter filter);

        void ClearResultOutput(Guid filterId);
        List<BsonDocument> GetFullResultOutput(ResultOutputFilter filter);
        #endregion

        #region TemplateCriteria
        List<TemplateCriteria> ListTemplateCriteriaByLevel3Id(Guid? criteriaLevel3Id);

        TemplateCriteria GetTemplateCriteriaById(Guid templateCriteriaId);

        IndicatorTemplate GetIndicatorTemplate(string number);

        GovernanceIndicatorTemplate GetGovernanceIndicatorTemplate(string number);

        //Entities.RiskRatings.RiskRatingIndicator GetRiskRatingsIndicatorTemplate(string number);

        List<TemplateCriteria> GetDataPointsByCriteriaLevel2IdAndChecks(Guid criteriaLevel2Id, List<TemplateCheck> checks);

        List<TemplateCriteria> ListTemplateCriteria();
        #endregion

        Dictionary<Guid, BsonDocument> GetScreeningDataFields(Guid filterId, List<Guid> companies);

        List<AnswerCategory> GetAnswerCategoryForRiskRating(TemplateCriteria criteria);
    }
}
